package com.example.innovate.service.impl;

import com.example.innovate.domain.AchievementCompetitionDO;
import com.example.innovate.domain.AchievementCompetitionDOExample;
import com.example.innovate.mapper.AchievementCompetitionDOMapper;
import com.example.innovate.service.AchieveCompetitionService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class AchieveCompetitionServiceImpl implements AchieveCompetitionService {

    @Autowired
    AchievementCompetitionDOMapper achievementCompetitionDOMapper;

    @Override
    public AchievementCompetitionDO addCompetition(AchievementCompetitionDO achievementCompetitionDO) {
        achievementCompetitionDOMapper.insertSelective(achievementCompetitionDO);
        return null;
    }

    @Override
    public void deleteCompetition(int id) {
        achievementCompetitionDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public AchievementCompetitionDO updateCompetiton(AchievementCompetitionDO achievementCompetitionDO) {
        achievementCompetitionDOMapper.updateByPrimaryKeySelective(achievementCompetitionDO);
        return achievementCompetitionDO;
    }

    @Override
    public AchievementCompetitionDO findCompetitionById(int id) {
        AchievementCompetitionDO achievementCompetitionDO = achievementCompetitionDOMapper.selectByPrimaryKey(id);
        return achievementCompetitionDO;
    }

    @Override
    public AchievementCompetitionDO findCompetitionByRemark(String remark) {
        AchievementCompetitionDOExample achievementCompetitionDOExample = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComRemarkEqualTo(remark);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        if(list.size()!=0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<AchievementCompetitionDO> findByUserId(int id,int pageNumber,int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComUserIdEqualTo(id)
                .andComIsTempEqualTo("false");
        PageHelper.startPage(pageNumber,pageSize);
        return achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
    }



    @Override
    public List<AchievementCompetitionDO> findAll(int pageNumber,int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample
                = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComIsTempEqualTo("false");
        PageHelper.startPage(pageNumber,pageSize);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        return list;
    }

    @Override
    public List<AchievementCompetitionDO> findAllNotPage() {
        AchievementCompetitionDOExample achievementCompetitionDOExample = new AchievementCompetitionDOExample();
        return achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
    }

    @Override
    public List<AchievementCompetitionDO> findAllByClassName(String className, int pageNumber, int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample
                = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComIsTempEqualTo("false")
                .andComClassNameEqualTo(className);
        PageHelper.startPage(pageNumber,pageSize);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        return list;
    }

    @Override
    public List<AchievementCompetitionDO> findAllExamine(int pageNumber, int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample
                = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComIsTempEqualTo("true");
        PageHelper.startPage(pageNumber,pageSize);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        return list;
    }

    @Override
    public List<AchievementCompetitionDO> findAllExamineByClass(String className, int pageNumber, int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample
                = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComIsTempEqualTo("true")
                .andComClassNameEqualTo(className);
        PageHelper.startPage(pageNumber,pageSize);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        return list;
    }

    @Override
    public List<AchievementCompetitionDO> findAllExamineByUserId(int userId, int pageNumber, int pageSize) {
        AchievementCompetitionDOExample achievementCompetitionDOExample = new AchievementCompetitionDOExample();
        achievementCompetitionDOExample.createCriteria()
                .andComUserIdEqualTo(userId)
                .andComIsTempEqualTo("true");
        PageHelper.startPage(pageNumber,pageSize);
        List<AchievementCompetitionDO> list = achievementCompetitionDOMapper.selectByExample(achievementCompetitionDOExample);
        return list;
    }



}
